#include "HTTPRequestInfo.h"

//TODO Check for Content-Length, if there read RequestBody
HTTPRequestInfo::HTTPRequestInfo(string Line)
{
	size_t Pos = Line.find(" ");
	if(Pos != string::npos)
	{
		mMethod = Line.substr(0, Pos);
		Line = Line.substr(Pos+1);
		size_t Pos = Line.find(" ");
		if(Pos != string::npos)
		{
			mResource = Line.substr(0, Pos);
			Line = Line.substr(Pos+1);
			mVersion = Line;
		}
		else
		{
			Valid = false;
			return;
		}
	}
	else
	{
		Valid = false;
		return;
	}

	Pos = mResource.find("?");

	if(Pos != string::npos)
	{
		if(mResource.length() > Pos)
		{
			mQueryString = mResource.substr(Pos+1);
		}
		mResource = mResource.substr(0, Pos);
	}

	if(mResource == "/")
	{
		mResource = "/index.html";
	}

	Pos = mResource.find("..");
	if(Pos != string::npos)
	{
		// Try and stay within boundaries.
		Valid = false;
		return;
	}

	Valid = true;
}

bool HTTPRequestInfo::IsValid()
{
	return Valid;
}

HTTPRequestInfo::HTTPRequestInfo()
{

}


HTTPRequestInfo::~HTTPRequestInfo()
{

}
